<?php
/*
 *      autartijob.php
 *      
 *      Copyright 2009 Michael Gyen <GyenMic@autartica.be>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
defined('_JEXEC') or die();
class AutartiJobsControllerAutartiJob extends AutartiJobsController{
function __construct(){
  parent::__construct();
  $this->registerTask( 'add', 'edit' );
  $this->registerTask( 'unpublish', 'publish');
}
function edit() {
  JRequest::setVar( 'view', 'autartijob' );  
  JRequest::setVar('hidemainmenu', 1);    
  $model = $this->getModel('autartijobcountries');
  $countries=$model->getData();
  JRequest::setVar( 'countries', $countries );  
  
  parent::display();
}

function save() {
  $model = $this->getModel('autartijob');
    if ($model->store($post)) {
      $msg = JText::_( 'JOB_SAVED' );
    } else {
      $msg = JText::_( 'JOB_ERROR_SAVING' );
    }
    $link = 'index.php?option=com_autartijobs';
    $this->setRedirect($link, $msg);
}  
function remove(){
  $model = $this->getModel('autartijob');
  if(!$model->delete()) {
    $msg = JText::_( 'JOB_ERROR_DELETING');
  } else {
    $msg = JText::_( 'JOB_DELETED' );
  }
  $this->setRedirect( 'index.php?option=com_autartijobs', $msg );
}
function publish(){
  $this->setRedirect( 'index.php?option=com_autartijobs');
  $db =& JFactory::getDBO();
  $user =& JFactory::getUser();
  $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
  $task = JRequest::getCmd( 'task' );
  $publish = ($task == 'publish');
  $n = count( $cid );
  if (empty( $cid )) {
    return JError::raiseWarning( 500, JText::_( 'No selection' ) );
  }
  JArrayHelper::toInteger( $cid );
  $cids = implode( ',', $cid );
  $query = 'UPDATE #__autartijob'
     . ' SET published = ' . (int) $publish
     . ' WHERE id IN ( '. $cids .' )'
     ;
  $db->setQuery( $query );
  if (!$db->query()) {
    return JError::raiseWarning( 500, $row->getError() );
  }
  $this->setMessage( JText::sprintf( $publish ? 'Published' : 'Not published',$n ) );
}
function cancel(){
  $msg = JText::_( 'OPERATION_CANCELLED' );
  $this->setRedirect( 'index.php?option=com_autartijobs', $msg );
}
}
?>

